using System.Collections.Generic;
using System.Linq;
using BusinessLogic.BusinessEntity.Entities;
using DataAccess.Services;
namespace BusinessLogic.Mappers.AccountCode
{
	internal class AccountMapper : MapperBase<Account, DataControl.Account>, IAccountMapper
	{
		public AccountMapper(IServiceManager serviceManager, IMapping<Account, DataControl.Account> mapping, IGatewayBase<DataControl.Account> gatewayBase)
			: base(serviceManager, gatewayBase, mapping)
		{
		}

		public bool Exists(string accountCode)
		{
			return ServiceManager.Account.Exists(accountCode);
		}

		public Account GetAccountByNumber(string accountCode)
		{
			DataControl.Account accountDTO = ServiceManager.Account.GetAccountByNumber(accountCode);

			Account account = Mapping.ToBE(accountDTO);
			account.Currency = MapperFactory.GetCurrencyMapper(ServiceManager).GetById((accountDTO.CurrencyFK));
			account.Accountee = MapperFactory.GetUserMapper(ServiceManager).GetByAccountCode(account.Number);

			return account;
		}

		public void UpdateBalance(int accountId, decimal balance)
		{
			ServiceManager.Account.UpdateBalance(accountId, balance);
		}

		public IEnumerable<Account> GetClientAccounts(int clientId)
		{
			return ServiceManager.Account.GetClientAccount(clientId).Select(account => Mapping.ToBE(account));
		}

		public IList<Account> GetAllAccounts()
		{
			return ServiceManager.Account.GetAllAccounts().Select(account => Mapping.ToBE(account)).ToList();
		}

		public Account GetAccountByID(int accountID)
		{
			return Mapping.ToBE(ServiceManager.Account.GetById(accountID));
		}
	}
}